<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>课程管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link  rel="stylesheet" type="text/css" href="css/four.css"/>
    <link rel="stylesheet" type="text/css" href="css/jqe/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="css/jqe/themes/icon.css"/>

    <script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript">
        $(function(){
        	 //初始化对话框
        	   $('#dw,#dwEdit,#dwRead,#dwJoin,#mycourses').window({
        		   onBeforeClose:function(){ 
        			   //取消时关闭等待框
        			   setTimeout(function(){ 
        				   sending.style.visibility = "hidden";
					   }, 250);
        	   }});
        	
       
              $(".btnAll").each(function(i,v){
        	   //变手型
        	     $(v).mouseover(function() {
    				$(this).css("cursor", "hand");
    			 }).mouseout(function() {
    				$(this).css("cursor", "pointer");
    			 });
        	   
        	   
        	   if($(v).html()=='【新增】'){
        		   $(v).click(function(){
        			   $('#dw').window("open");
        		   });
        	   }else if($(v).html()=='【编辑】'){
        		   $(v).click(function(){
        			   //ajax
        			  /*  $.get("ajOneCou.do?kcid="+ $(v).prop("lang")+"&x="+Math.random(),function(jsonTxt){
        				   var jsonObj = eval("("+jsonTxt+")");
        				   $("#upd_kcid").val(jsonObj.kcid);
        				   $("#upd_kcname").val(jsonObj.kcname);
        				   $("#upd_kcdesc").html(jsonObj.kcdesc);
        				   $('#dwEdit').window("open");
        			   }); */
        			   
        			   $.ajax({
        				   type:"POST",
        				   url:"ajOneCou.do",
        				   data:"cid="+ $(v).prop("lang")+"&time="+new Date().getTime(),
        				   success:function(msg){
        					   if(msg.head='ok'){
        						   $("#upd_kcid").val(msg.body.cid);
                				   $("#upd_kcname").val(msg.body.cname);
                				   $("#upd_kcdesc").html(msg.body.cinfomation);
                				   $('#dwEdit').window("open");
        					   }
        				   }
 
        			   });
        			   
        		   });
        	   }else if($(v).html()=='【删除】'){
        		   $(v).click(function(){
        			  if(confirm("确认删除'"+$(v).prop("title")+"'?")){
        				  location.href="delCourse.do?cid="+$(v).prop("lang"); 
        			  }
        		   });
        	   }else if($(v).html()=='【加入课程】'){
        		  $(v).click(function(){
        			  $.ajax({
        				  type:"GET",
        				  url:"ajAllCou.do",
        				  success:function(list){
        					  $.each(list,function(i,course){
        						  $("#selectCou").append("<option value="+course.cid+">"+course.cname+"</option>");
        					  })
        					  $('#dwJoin').window("open");
        				  }
        			  })
        		  })
        	   }else if($(v).html()=='【查看】'){
        		   $(v).click(function(){
        			   $.ajax({
        				   type:"POST",
        				   url:"ajOneCou.do",
        				   data:"cid="+ $(v).prop("lang")+"&time="+new Date().getTime(),
        				   success:function(msg){
        					   if(msg.head='ok'){
                				   $("#read_kcname").html(msg.body.cname);
                				   $("#read_kcdesc").html(msg.body.cinfomation);
                				   $('#dwRead').window("open");
        					   }
        				   }
        			   });
        		   })
        	   }else if($(v).html()=='【我的课程】'){
        		   $(v).click(function(){
        			   $.ajax({
        				   type:"POST",
        				   url:"getMycourse.do",
        				   data:"uid="+$(v).prop("lang"),
        				   success:function(item){
        					   if(item.head=='ok'){
        						   $.each(item.body,function(i,course){
              						  $("#listCou").append("<li>"+course.cname+"</li>");
              					  })
        					   }else{
        						   $("#mm").html("你还没加入任何课程！");
        					   }
        					   $('#mycourses').window("open");
        				   }
        			   });
        		   })
        	   }  
           }); 
              
              $("#che_all").click(function(){
             	 if(this.checked){
             		 $("input[name='item_id']").prop("checked",true);
             	 }else{
             		 $("input[name='item_id']").prop("checked",false);
             	 } 
               });
                 
               $("#del_all").click(function(){
             	    
             	    var item=" ";
             	$("input[name='item_id']").each(function(i,v){
             		if($(v).prop("checked")==true){
             			item+=$(v).val()+",";
             		}
             	});
             	
             	  if(confirm("确认删除选中课程?")){
             		  location.href="delAll.do?cids="+item;  
     			  }
             	   
             	
               }); 
        });
    </script>
</head>
<body>
<!-- 包含等待框 -->
	<jsp:include page="../waittable.jsp" flush="true" />
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
				<span class="btnAll" lang="${sessionScope.user.userid}" stype="float:right">【我的课程】</span><br/><br/>
		<tr valign="top">
			<td bgcolor="#FFFFFF">
			<table width="96%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#aec3de">
					<tr align="left" bgcolor="#F2FDFF">
						<td colspan="6" class="optiontitle">课程设置表</td>
					</tr>
					<tr align="center">
					     <td align="center" bgcolor="#ebf0f7"><input type="checkbox" id="che_all"/>全选/不选</td>
					    <td align="center" bgcolor="#ebf0f7">课程ID</td>
						<td align="center" bgcolor="#ebf0f7">课程名称</td>
					
						<td align="center" bgcolor="#ebf0f7">课程描述</td>
						<td align="center" bgcolor="#ebf0f7">操作<c:choose>
						<c:when test="${sessionScope.user.role == 1}"><span class="btnAll">【新增】</span></c:when>
						<c:otherwise><span class="btnAll">【加入课程】</span>
						</c:otherwise></c:choose>  <span id="del_all">【批量删除】</span></td>
					</tr>             
					<c:forEach items="${page.results}" var="course">
						<tr align="center" bgcolor="#FFFFFF">
						    <td align="center" ><input type="checkbox" name="item_id" value="${course.cid }"/></td>
						    <td align="center" >${course.cid }</td>
							<td align="center">${course.cname }</td>
							<td align="center">${course.cinfomation}</td>
							<td align="center">
							         <span class="btnAll" lang="${course.cid}">【查看】</span>
									<c:if test="${sessionScope.user.role == 1}">
									| <span class="btnAll" lang="${course.cid}">【编辑】</span>
									</c:if>
								    | <span class="btnAll" lang="${course.cid }" title="${course.cname }">【删除】</span>  
							</td>
						</tr>
					</c:forEach>
					<tr align="right" bgcolor="#ebf0f7">
							<td colspan="6">
							<jk:page totalPage="${page.totalPage}" pageNo="${page.pageNo}" totalRecord="${page.totalRecord}"
                                url="getAllCourse.do" />
							</td>	
					</tr>

	         </table>
	        </td>
	     </tr>
	 </table>
	 <div id="dwRead" class="easyui-window" title="查看课程表" data-options="modal:true,minimizable:false,closed:true,maximizable:false,iconCls:'icon-save'" style="width:300px;height:200px;padding:10px;display: none;">
		     课程名称：<span id="read_kcname"></span><br/><br/>
		       课程描述 ：<textarea name="cinfomation" rows="3" cols="30" id="read_kcdesc"></textarea><br/><br/>
	</div>
	<div id="mycourses" class="easyui-window" title="我的课程" data-options="modal:true,minimizable:false,closed:true,maximizable:false,iconCls:'icon-save'" style="width:300px;height:200px;padding:10px;display: none;">
		     您的课程：<ul id="listCou">
		     </ul>
		     <span id="mm"></span>
	</div>
	<div id="dwJoin" class="easyui-window" title="课程列表" data-options="modal:true,minimizable:false,closed:true,maximizable:false,iconCls:'icon-save'" style="width:300px;height:200px;padding:10px;display: none;">
		<form action="joinCourse.do" method="post">
		<input name="uid" type="hidden" value="${sessionScope.user.userid}"/>
		     课程名称：<select id="selectCou" name="cid">
		     <option value="0">--请选择要加入的课程--</option>
		     </select>
		      <input type="submit" value="提交"/><br/>
		</form>
	</div>
	
	<div id="dw" class="easyui-window" title="新增课程表" data-options="modal:true,minimizable:false,closed:true,maximizable:false,iconCls:'icon-save'" style="width:300px;height:200px;padding:10px;display: none;">
		<form action="addCourse.do" method="post">
		     课程名称：<input name="cname"/><br/><br/>
		   <!--   创建时间:<input name="cdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/> <br/><br/> -->
		     课程描述 ：<textarea name="cinfomation" rows="3" cols="30"></textarea><br/><br/>
		      <input type="submit" value="提交"/><br/>
		</form>
	</div>
	
	
	 <div id="dwEdit" class="easyui-window" title="修改课程表" data-options="modal:true,minimizable:false,closed:true,maximizable:false,iconCls:'icon-save'" style="width:300px;height:200px;padding:10px;display: none;">
		<form action="updCourse.do" method="post">
		<input name="cid" id="upd_kcid" type="hidden"   />
		     课程名称：<input name="cname" id="upd_kcname"   /><br/><br/>
		     课程描述 ：<textarea name="cinfomation" rows="3" cols="30" id="upd_kcdesc"></textarea><br/><br/>
		      <input type="submit" value="修改"/><br/>
		</form>
	</div>
</body>
</html>
